<?php

namespace Biz\model\admin;

use Doraemon\pockets\publicTrait\CheckConstants;

class ReplaceWikiLog extends \Doraemon\pockets\datebase\BaseDbModel
{

    use CheckConstants;

    const _CONFIG_FILE_ = 'db_admin';

    const _CONFIG_SELECT_ = 'db_shop_admin';

    const _DATABASE_ = 'shop_admin';

    const _TABLE_NAME = 'replace_wiki_log';


    const _TYPE_PREFIX_ = "TYPE_";


    const TYPE_PHOTO_RELA_WIKI = 1; // 图片关联 wiki

    const TYPE_GOODS_BIND_WIKI = 2; // goods 绑定 wiki

    const TYPE_WIKI_RELA_USER = 3; // wiki 用户收藏

    const TYPE_WIKI_COUNTER = 4; // wiki 计数

    const TYPE_WIKI_ID_REPLACE = 5; //wiki_id 删除

    const TYPE_WIKI_ACTION_STATUS = 6; //wiki_id 收藏买过状态更改


    public static function addLog($wiki_id, $replace_wiki_id, $type, $action_uid, array $source_data = [], array $target_data = [])
    {
        if (self::checkConstants(self::_TYPE_PREFIX_, $type)) {
            $data = [];
            $data['action_uid'] = $action_uid;
            $data['type_id'] = $type;
            $data['wiki_id'] = $wiki_id;
            $data['replace_wiki_id'] = $replace_wiki_id;
            $data['source_data'] = json_encode($source_data, JSON_UNESCAPED_UNICODE);
            $data['target_data'] = json_encode($target_data, JSON_UNESCAPED_UNICODE);
            $data['add_time'] = date("Y-m-d H:i:s");

            self::insert($data);
            return self::id();

        } else {

            throw new \Exception('参数类型不正确');

        }
    }

}